package com.plugin.uniapp.dialog;

import android.graphics.SurfaceTexture;
import android.view.Surface;
import android.view.TextureView;
import androidx.annotation.NonNull;
import com.plugin.uniapp.R;

public class VideoView extends BaseView {
    TextureView  textureView;

    public VideoView(MultiViewDialog dialog) {
        super(dialog, R.layout.view_video);
        initVideo();
    }

    private void initVideo() {
        if (textureView == null) {
            textureView = layout.findViewById(R.id.texture_view);
            textureView.setSurfaceTextureListener(new TextureView.SurfaceTextureListener() {
                @Override
                public void onSurfaceTextureAvailable(@NonNull SurfaceTexture surface, int width, int height) {
                    dialog.currPlayer.changeSerface(new Surface(surface));
                }

                @Override
                public void onSurfaceTextureSizeChanged(@NonNull SurfaceTexture surface, int width, int height) {

                }

                @Override
                public boolean onSurfaceTextureDestroyed(@NonNull SurfaceTexture surface) {
                    log("SurfaceTexture 已被销毁");
                    return false;
                }

                @Override
                public void onSurfaceTextureUpdated(@NonNull SurfaceTexture surface) {

                }
            });
        }
    }

    public void resumeSerface(){
        dialog.currPlayer.resumeSerface();
    }
}
